package com.wty.basic.objectReference;

import com.wty.basic.pojo.School;
import com.wty.basic.pojo.Student;

/**
 * 深拷贝 把拷贝的对象中的对象属性也实现cloneable接口 并在clone方法中添加逻辑
 */
public class CloneTest2 {
    public static void main(String args[]) throws CloneNotSupportedException {
        Student stu1=new Student("wty",18,new School("tust",2000));
        Student stu2= (Student) stu1.clone();

        System.out.println("更改前stu1信息");
        System.out.println(stu1.getName());
        System.out.println(stu1.getAge());
        System.out.println(stu1.getSchool().getName());

        System.out.println("stu2更改后信息");
        stu2.setName("kids");
        stu2.setAge(23);
        /**
         * 浅拷贝引用类型只是复制了引用，没有开辟新的地址
         */
        stu2.getSchool().setName("test");
        System.out.println(stu2.getName());
        System.out.println(stu2.getAge());
        System.out.println(stu2.getSchool().getName());


        System.out.println("更改后stu1信息");
        System.out.println(stu1.getName());
        System.out.println(stu1.getAge());
        System.out.println(stu1.getSchool().getName());
    }
}
